﻿@model IEnumerable<BskLeague.Models.Team>

@{
    ViewBag.Title = "Lista drużyn";
    Func<int, int, int> subtract = (a,b) =>a-b;
}

<center><h2>Lista drużyn</h2>

<table cellspacing="0" cellpadding="0" border="1" width="80%">
    <tr><td colspan="5" align="center">
        <
        @for(int i=0; i<@ViewBag.LettersList.Count; i++)
        {
            <text>
            <font size="2">@Html.ActionLink((string)@ViewBag.LettersList[i].ToString(), "Index", new { letter = @ViewBag.LettersList[i] })
            <text>-</text>
            </text>
        }
        @Html.ActionLink("Pokaż wszystkie ", "Index", new { letter = '0' })</font>
        >
    </td></tr>

    <tr>
        <th style="text-align:center;">Nazwa drużyny</th>
        <th style="text-align:center;">Kapitan</th>
        <th style="text-align:center;">Rozegranych meczy (wygrane/przegrane)</th>
    </tr>
    @{int j=0;
    foreach(var t in Model)
        {
            <tr style="text-align:center;">
                <td>@Html.ActionLink(t.TeamName, "Details", new { id = @t.TeamId})</td>
                <td>@Html.ActionLink(t.ChefPlayer.PlayerName + " " + t.ChefPlayer.PlayerSurname, "Details/"+t.ChefPlayer.PlayerId, "Players")</td>
                <td>@(ViewBag.Matches[j].Won + @ViewBag.Matches[j].Lost) (@ViewBag.Matches[j].Won/@ViewBag.Matches[j++].Lost)</td>
            </tr>
        }
    }
    @if (@ViewBag.TotalItemsCount > @ViewBag.Take)
    {
        int temp = @ViewBag.TotalItemsCount / @ViewBag.Take;
        temp = ((@ViewBag.TotalItemsCount % @ViewBag.Take) != 0) ? ++temp : temp;
        <tr><th colspan="3"><center><
            @for (int i = 0; i < temp; i++)
            {
                if (@ViewBag.From / @ViewBag.Take == i)
                {<text>@(i + 1) </text>}
                else
                {
                @Html.ActionLink((i + 1).ToString(),
                                null,
                                "Team",
                                new
                                {
                                    letter = @ViewBag.Letter,
                                    from = (i * @ViewBag.Take),
                                    take = @ViewBag.Take
                                },
                                null)
                <text> </text>
                }
            }>
        </center></th></tr>
    }
    <tr>
        <td colspan="5" align="center">
            @using (Html.BeginForm("Index", "Team", FormMethod.Get))
            {
                <input type="hidden" name="letter" id="letter" value="@ViewBag.Letter" />
                <text>Wyświetl </text>@Html.DropDownList("take", new SelectList(new[]{new KeyValuePair<string, int>("5",5),
                                                        new KeyValuePair<string, int>("7", 7),
                                                        new KeyValuePair<string, int>("10", 10)},
                                                        "Value", "Key"));
                <text>pozycji na stronie.</text>                                 
                <input type="submit" value="Zatwierdź" />
            }
        </td>
    </tr>
</table>

</center>